package ecitys.gcs

import java.util.Date;
import ecitys.types.Money;
import ecitys.util.*
import static org.junit.Assert.*

import org.hibernate.validator.AssertFalse;
import org.hibernate.validator.AssertTrue;
import org.junit.*
import grails.test.*

class VerbaTests extends GrailsUnitTestCase{
	def indice1 
	def data 
	def v 
	def vlIndice 
	def verba1 
	def calc
	
	protected void setUp() {
        super.setUp()
		
		mockDomain Verba, []
		mockDomain Indice, []
		mockDomain ValorIndice, []
		//mockDomain CalculoVerba, []

		indice1 = new Indice(indice:'Indice-001')
		indice1.save()
		
		data = new Date()
		v = Money.newMoneyFromReal(100)
		
		vlIndice = new ValorIndice(dataDeVigencia:data, valor:v, indice:indice1)
		vlIndice.save()
		
		verba1 = new Verba(codigoDaVerba:'1', nomeDaVerba:'Salario', NaturezaDaVerba:1, baseCalculoInss:1,
			baseCalculoIrf:1, baseCalculoFgts:1, baseCalculoRais:1, baseCalculoDsr:1,
			baseCalculoSf:1, comprovanteRendimentosPagos:1, opcaoBaseCalculo:1,proporcional:1,
			mesDeCalculo:0, tipoDeCalculo:0,	percentual:v,valorBase:v,fatorDeDivisao:v,
			fatorDeMultiplicacao:v,verbaConsignada:false,indice:indice1, verbaBase:null,
			calculo:null);
		
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testConstraints() {
		
		assertTrue indice1.validate()
		
		assertTrue vlIndice.validate()

		assertTrue verba1.validate()
		
    }
	
	void testCalculoVerbaPorIndice(){
		
		assertTrue "Tipo de Calculo: Por Indice", (verba1.opcaoBaseCalculo==1)
		
		calc = new CalculoPorIndice(indice1, verba1)
		
		//assertTrue calc.validate()           
		
		assertFalse calc==null
		
		verba1.calculo = calc
		
		assertFalse verba1.calculo.doCalculo()==1
		 
	} 
}
